package cn.stylefeng.guns.modular.api.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.api.entity.Client;
import cn.stylefeng.guns.modular.api.model.params.ClientParam;
import cn.stylefeng.guns.modular.api.service.ClientService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 客户控制器
 *
 * @author samwuu
 * @Date 2019-09-27 14:13:45
 */
@Controller
@RequestMapping("/api/client")
public class ClientController extends BaseController {

    private String PREFIX = "/client";

    @Autowired
    private ClientService clientService;

    /**
     * 跳转到主页面
     *
     * @author samwuu
     * @Date 2019-09-27
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/client.html";
    }

    /**
     * 新增页面
     *
     * @author samwuu
     * @Date 2019-09-27
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/client_add.html";
    }

    /**
     * 编辑页面
     *
     * @author samwuu
     * @Date 2019-09-27
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/client_edit.html";
    }

    /**
     * 新增接口
     *
     * @author samwuu
     * @Date 2019-09-27
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(ClientParam clientParam) {
        this.clientService.add(clientParam);
        return ResponseData.success();
    }

    /**
     * 更新接口
     *
     * @author samwuu
     * @Date 2019-09-27
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(ClientParam clientParam) {
        this.clientService.update(clientParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author samwuu
     * @Date 2019-09-27
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(ClientParam clientParam) {
        this.clientService.delete(clientParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author samwuu
     * @Date 2019-09-27
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(ClientParam clientParam) {
        Client detail = this.clientService.getById(clientParam.getClientId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author samwuu
     * @Date 2019-09-27
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(ClientParam clientParam) {
        return this.clientService.findPageBySpec(clientParam);
    }

}


